package com.zhanbo.zhanbowymusic.dialog;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.mwx.baselib.utils.ToastUtils;
import com.zhanbo.zhanbowymusic.R;

public class VipBuyPop extends PopupWindow implements View.OnClickListener {
    private final TextView tv_user_agreement;
    private final ImageView iv_close;
    private Context mContext;
    @SuppressLint("MissingInflatedId")
    public VipBuyPop(Context context) {
        super(context);
        mContext = context;
        View view = LayoutInflater.from(context).inflate(R.layout.pop_buy_vip,null);
        setContentView(view);
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.MATCH_PARENT);

        setBackgroundDrawable(null);
        setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED);
        setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        setOutsideTouchable(false);
        setFocusable(true);
       tv_user_agreement= view.findViewById(R.id.tv_user_agreement);
        iv_close= view.findViewById(R.id.iv_close);
       initData();
       initListener();
    }

    private void initListener() {
        iv_close.setOnClickListener(this);
    }

    private void initData() {
        SpannableStringBuilder span = new SpannableStringBuilder();
        span.append("开通会员代表接受《会员协议》、《连续包月服务协议》");
        span.setSpan(new ForegroundColorSpan(mContext.getResources().getColor(R.color.color_text)),0,8,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        ClickableSpan clickableSpan = new ClickableSpan() {
            @Override

            public void onClick(@NonNull View view) {
                ToastUtils.showShortToast(mContext,"隐私政策");
            }

        };

        ClickableSpan clickableSpan2 = new ClickableSpan() {
            @Override

            public void onClick(@NonNull View view) {
                ToastUtils.showShortToast(mContext,"隐私政策");
            }

        };

//        span.setSpan(clickableSpan,0,4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        span.setSpan(clickableSpan2,5,9, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        tv_user_agreement.setText(span);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_close:
                dismiss();
                break;
        }
    }
}
